/*
 * Copyright 2016 Yan Zhenjie
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.BuildingStyle;
import com.jiayang.hhotel.listener.OnItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by YOLANDA on 2016/7/22.
 */
public class BuildingStyleAdapter extends SwipeMenuAdapter<BuildingStyleAdapter.DefaultViewHolder> {
    private Context context;
    private List<BuildingStyle> buildingStyles;
    private int i = 0;
    private OnItemClickListener mOnItemClickListener;

    public BuildingStyleAdapter(List<BuildingStyle> titles, Context context) {
        this.buildingStyles = titles;
        this.context=context;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemCount() {
        return buildingStyles == null ? 0 : buildingStyles.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.listitem_buildingstyle, parent, false);
    }

    @Override
    public BuildingStyleAdapter.DefaultViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        DefaultViewHolder viewHolder = new DefaultViewHolder(realContentView);
        viewHolder.mOnItemClickListener = mOnItemClickListener;
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(BuildingStyleAdapter.DefaultViewHolder holder, int position) {
            holder.tvDaima.setText(buildingStyles.get(position).getName());
            holder.tvChinese.setText(buildingStyles.get(position).getChindes());
            holder.tvEnglish.setText(buildingStyles.get(position).getEngdes());
            switch (i){
                case 0:
                    holder.lin1.setBackgroundResource(R.drawable.style1);
                    i++;
                    break;
                case 1:
                    holder.lin1.setBackgroundResource(R.drawable.style2);
                    i++;
                    break;
                case 2:
                    holder.lin1.setBackgroundResource(R.drawable.style3);
                    i++;
                    break;
                case 3:
                    holder.lin1.setBackgroundResource(R.drawable.style4);
                    i++;
                    break;
                case 4:
                    holder.lin1.setBackgroundResource(R.drawable.style5);
                    i=0;
                    break;
            }
    }

    static class DefaultViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tvChinese,tvEnglish,tvDaima;
        OnItemClickListener mOnItemClickListener;
        LinearLayout lin1;
        public DefaultViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            tvDaima= (TextView) itemView.findViewById(R.id.bsitem_tv_daima);
            tvChinese= (TextView) itemView.findViewById(R.id.bsitem_tv_chinese);
            tvEnglish= (TextView) itemView.findViewById(R.id.bsitem_tv_english);
            lin1= (LinearLayout) itemView.findViewById(R.id.bsitem_lin);

        }


        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClick(getAdapterPosition());
            }
        }
    }

}
